package com.example.yls.demod;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by yls on 2019/5/13.
 */

public class MyView extends View {
    private Paint paint = new Paint();
    private int progress = 88;

    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        paint.setAntiAlias(true);
        paint.setDither(true);
        paint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(20);
        canvas.drawCircle(350, 400, 200, paint);

        paint.setStrokeWidth(2);
        paint.setTextSize(40);
        canvas.drawText("运动消耗", 280, 360, paint);
        canvas.drawText(progress + "%", 320, 420, paint);
        canvas.drawText("Kcal", 310, 480, paint);

        paint.setColor(Color.GREEN);
        paint.setStrokeWidth(20);
        canvas.drawArc(150, 200, 550, 600,
                -90, 360*progress/100,
                false, paint);
    }

    public void setProgress(int progress) {
        this.progress = progress;
        invalidate();
    }
}
